package org.baojie.parser;

import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statements;
import org.baojie.ParserState;
import org.baojie.SourceDetail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author baojie
 * @date 2022/6/14 下午4:34
 */
public abstract class BaojieParser implements Parser {

    //单利模式
    protected final Logger log = LoggerFactory.getLogger(getClass());

    protected final ParserState parser0(String sqls, SourceDetail detail) {
        final ParserState parserState = ParserState.create(sqls, detail);
        try {
            Statements states = CCJSqlParserUtil.parseStatements(sqls);
            parserState.setStates(states);
        } catch (Throwable t) {
            parserState.setError(t);
            log.error("SQLParser err = " + t.getMessage() + ", detail = " + detail, t);
        }
        return parserState;
    }

}
